home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / lib / tk / entry.tcl < prev    next >
Text File  |  1995-07-21  |  3KB  |  75 lines

  1. # entry.tcl --
  2. #
  3. # This file contains Tcl procedures used to manage Tk entries.
  4. #
  5. # $Header: /user6/ouster/wish/library/RCS/entry.tcl,v 1.7 93/10/18 17:15:23 ouster Exp $ SPRITE (Berkeley)
  6. #
  7. # Copyright (c) 1992-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27.  
  28. # The procedure below is invoked to backspace over one character
  29. # in an entry widget.  The name of the widget is passed as argument.
  30.  
  31. proc tk_entryBackspace w {
  32.     set x [expr {[$w index insert] - 1}]
  33.     if {$x != -1} {$w delete $x}
  34. }
  35.  
  36. # The procedure below is invoked to backspace over one word in an
  37. # entry widget.  The name of the widget is passed as argument.
  38.  
  39. proc tk_entryBackword w {
  40.     set string [$w get]
  41.     set curs [expr [$w index insert]-1]
  42.     if {$curs < 0} return
  43.     for {set x $curs} {$x > 0} {incr x -1} {
  44.     if {([string first [string index $string $x] " \t"] < 0)
  45.         && ([string first [string index $string [expr $x-1]] " \t"]
  46.         >= 0)} {
  47.         break
  48.     }
  49.     }
  50.     $w delete $x $curs
  51. }
  52.  
  53. # The procedure below is invoked after insertions.  If the caret is not
  54. # visible in the window then the procedure adjusts the entry's view to
  55. # bring the caret back into the window again.  Also, try to keep at
  56. # least one character visible to the left of the caret.
  57.  
  58. proc tk_entrySeeCaret w {
  59.     set c [$w index insert]
  60.     set left [$w index @0]
  61.     if {$left >= $c} {
  62.     if {$c > 0} {
  63.         $w view [expr $c-1]
  64.     } else {
  65.         $w view $c
  66.     }
  67.     return
  68.     }
  69.     set x [expr [winfo width $w] - [lindex [$w config -bd] 4] - 1]
  70.     while {([$w index @$x] < $c) && ($left < $c)} {
  71.     set left [expr $left+1]
  72.     $w view $left
  73.     }
  74. }
  75.